package model;
import java.sql.*;
/**
 *
 * @author N V Reddy
 */
public class LoginCheck {
    Connection con;
    

public boolean getConnection(String db)    {
    String url="jdbc:mysql://localhost:3306/";
    String driver;
    try
        {
        driver="com.mysql.jdbc.Driver";
        Class.forName(driver);
        con=DriverManager.getConnection(url+db,"root","");
        return true;
        }
    catch(Exception e)
        {
            System.out.println("Exception is :"+e);
        }
    return false;
    }
public boolean validation(String username,String password){
    try{
        Statement st = con.createStatement();
        ResultSet res= st.executeQuery("SELECT * FROM  registeredmem");
        while(res.next())
            {
                if((username.equals(res.getString(1))) && (password.equals(res.getString(2)))){
                    return true;
                }
            }

    }
    catch(Exception e){
        System.out.println("Exception is :"+e);
    }
    
    return false;
}
public boolean registration(String username,String password){
    try{
       PreparedStatement pst1=con.prepareStatement("insert into `registeredmem`(`UserName`,`Password`) "+ "values(?,?)");
        pst1.setString(1,username);
        pst1.setString(2,password);
        pst1.executeUpdate();
        return true;
    }
    catch(Exception e){
        System.out.println("Exception is :"+e);
    }
    return false;
}
public void closeConnection(){
    try{
        con.close();
    }
    catch(Exception e){
        System.out.println("Exception is : "+e);
    }
}

    
}
